package com.bqtv.sport.ui.im

import android.content.Context
import android.content.Intent
import android.text.TextUtils
import android.view.View
import com.bqtv.sport.app.AppActivity
import com.bqtv.sport.databinding.ActivityMyGroupListBinding
import com.tencent.qcloud.tuikit.tuicontact.bean.ContactItemBean
import com.tencent.qcloud.tuikit.tuicontact.classicui.util.ClassicUIUtils
import com.tencent.qcloud.tuikit.tuicontact.classicui.widget.ContactListView
import com.tencent.qcloud.tuikit.tuicontact.interfaces.IContactListView
import com.tencent.qcloud.tuikit.tuicontact.presenter.ContactPresenter

class MyGroupListActivity : AppActivity<ActivityMyGroupListBinding>() {
    private lateinit var presenter: ContactPresenter
    companion object {
        fun start(context: Context) {
            val intent = Intent(context, MyGroupListActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun getViewBinding() = ActivityMyGroupListBinding.inflate(layoutInflater)

    override fun initView() {

    }

    override fun initData() {


        initListener()
    }

    public override fun onResume() {
        super.onResume()
        loadDataSource()
    }

    private fun initListener() {
        binding.groupList.setOnItemClickListener(object : ContactListView.OnItemClickListener {
            override fun onItemClick(position: Int, contact: ContactItemBean) {
                var chatName = contact.getId()
                if (!TextUtils.isEmpty(contact.getRemark())) {
                    chatName = contact.getRemark()
                } else if (!TextUtils.isEmpty(contact.getNickName())) {
                    chatName = contact.getNickName()
                }
                ClassicUIUtils.startChatActivity(
                    contact.getId(),
                    ContactItemBean.TYPE_GROUP,
                    chatName,
                    contact.getGroupType()
                )
            }
        })
    }

    override fun onClick(view: View) {
        super.onClick(view)
        when (view) {

        }
    }

    fun loadDataSource() {
        presenter = ContactPresenter()
        presenter.setFriendListListener()
        binding.groupList.setIsGroupList(true)
        binding.groupList.setPresenter(presenter)
        presenter.setContactListView(binding.groupList)
        binding.groupList.loadDataSource(IContactListView.DataSource.GROUP_LIST)
    }
}